// SPDX-License-Identifier: GPL-3.0-or-later

import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import Fk
import Fk.Components.LunarLTK
import Fk.Pages.LunarLTK
import Fk.Components.Common

GraphicsBox {
  id: root

  property var cards: []
  property var names: []
  property string prompt

  title.text: prompt !== "" ? Util.processPrompt(prompt) : ""
  width: 50 + Math.max(4, cards.length) * 100
  height: 220

  Component {
    id: cardDelegate
    GeneralCardItem {
      name: modelData
      autoBack: false
      selectable: true

      onRightClicked: {
        roomScene.startCheat("GeneralDetail", { generals: [modelData] });
      }
    }
  }

  
  Row {
    id: generalArea
    x: 20
    y: 35
    spacing: 10
    Repeater {
      id: to_select
      model: cards
      delegate: cardDelegate
    }
  }

  Item {
    y : 80
    width: parent.width
    height: parent.height

    Row {
      anchors.centerIn: parent
      Layout.fillWidth: true
      spacing: 10

      Repeater {
        model: names

        MetroButton {
          width: 93
          height: 30
          textFont.pixelSize : modelData.length > 4 ? Math.ceil(80 / modelData.length) : 18
          text: Util.processPrompt(modelData)
          enabled: true

          onClicked: {
            close();
            roomScene.state = "notactive";
            ClientInstance.replyToServer("", modelData);
          }
        }
      }
    }
  }


  function loadData(data) {
    [cards, names, prompt] = data
  }
}

